<template>
    <div class="app-container">

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['datamanage:sensitive:add']">新增</el-button>
            </el-col>

        </el-row>
        <el-table v-if="refreshTable" v-loading="loading" :data="sensitiveList" row-key="id">
            <el-table-column prop="sensitives" label="敏感词" :show-overflow-tooltip="true" width="160"></el-table-column>
            <el-table-column label="创建时间" align="center" prop="createdTime">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createdTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['datamanage:sensitive:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['datamanage:sensitive:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 添加或修改敏感词对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="680px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="菜单名称" prop="sensitives">
                            <el-input v-model="form.sensitives" placeholder="请输入菜单名称" />
                        </el-form-item>
                    </el-col>

                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
  
<script>
import { listSensitive, delSensitive, addSensitive, updateSensitive } from "@/api/datamanage/sensitive";

export default {
    name: "sensitive",
    // dicts: ['sys_show_hide', 'sys_normal_disable'],
    data() {
        return {
            // 遮罩层
            loading: true,
            // 敏感词表格树数据
            sensitiveList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 重新渲染表格状态
            refreshTable: true,
            // 查询参数
            queryParams: {
                sensitives: undefined,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                sensitives: [
                    { required: true, message: "敏感词名称不能为空", trigger: "blur" }
                ],
            }
        };
    },
    created() {
        this.getList();
    },
    methods: {
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: undefined,
                sensitives: undefined,
                isFrame: "1",
                isCache: "0",
                visible: "0",
                status: "0"
            };
            this.resetForm("form");
        },
        /** 查询敏感词列表 */
        getList() {
            this.loading = true;
            listSensitive(this.queryParams).then(response => {
                this.sensitiveList = response.data;
                this.loading = false;
            });
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.open = true;
            this.title = "添加敏感词";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            this.form = row;
            this.open = true;
            this.title = "修改敏感词";
            console.log("---------------------"+row.id)
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != undefined) {
                        updateSensitive(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addSensitive(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            this.$modal.confirm('是否确认删除名称为"' + row.sensitives + '"的数据项？').then(function () {
                return delSensitive(row.sensitiveId);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        }
    }
};
</script>
  